package com.heatingcharge.controller.unit;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.ResHouseDTO;
import com.heatingcharge.entity.unit.ResHouse;
import com.heatingcharge.param.ResHouseParam;
import com.heatingcharge.service.unit.IResHouseService;
import com.heatingcharge.vo.TreeVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 房屋信息 前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/res-house")
public class ResHouseController {

    @Autowired
    IResHouseService resHouseService;

    @ApiOperation(value = "分页获取房屋信息",notes = "分页获取房屋信息")
    @GetMapping
    public R getHouse(Page page, ResHouseDTO resHouseDTO){
        IPage<ResHouseDTO> zoneIPage = resHouseService.getHouses(page, resHouseDTO);
        return R.ok(zoneIPage);
    }

    @ApiOperation(value = "获取全部房屋信息",notes = "获取全部房屋信息")
    @GetMapping("/all")
    public R getAllHouse(ResHouseDTO resHouseDTO){
        List<TreeVo> zones = resHouseService.getHouses(resHouseDTO);
        return R.ok(zones);
    }

    @ApiOperation(value = "新增房屋",notes = "新增房屋")
    @PostMapping
    public R saveHouse(@RequestBody ResHouseParam resHouseParam){
        if (resHouseService.save(resHouseParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新房屋",notes = "更新房屋")
    @PutMapping
    public R updateHouse(@RequestBody ResHouseParam resHouseParam){
        if (resHouseService.update(resHouseParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "入网",notes = "入网")
    @PutMapping("/net")
    public R net(@RequestBody ResHouseParam resHouseParam){
        if (resHouseService.net(resHouseParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "退网",notes = "退网")
    @PutMapping("/unet")
    public R unet(@RequestBody ResHouseParam resHouseParam){
        if (resHouseService.unet(resHouseParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "发卡",notes = "发卡")
    @PutMapping("/register")
    public R register(@RequestBody ResHouseParam resHouseParam){
        if (resHouseService.register(resHouseParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "销卡",notes = "销卡")
    @PutMapping("/destory")
    public R destory(@RequestBody ResHouseParam resHouseParam){
        if (resHouseService.destory(resHouseParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "删除房屋",notes = "根据主键ID删除房屋")
    @DeleteMapping("/{id}")
    public R delHouse(@PathVariable("id") Integer id){
        if (resHouseService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }

}

